home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / DJGPP / BCCGRX12.ZIP / contrib / bcc2grx / test / htmext.inc < prev    next >
Text File  |  1993-06-04  |  7KB  |  268 lines

  1.  
  2. /* ------------------------------------------------------------------- */
  3. /* ----                     New demo routines                     ---- */
  4. /* ------------------------------------------------------------------- */
  5.  
  6.  
  7. int _max(int a, int b)
  8. {
  9.   return ( a>b ? a : b );
  10. }
  11.  
  12. int _min(int a, int b)
  13. {
  14.   return ( a<b ? a : b );
  15. }
  16.  
  17. void ShiftDac(char pal[][3])
  18. {
  19.   int r,g,b;
  20.   int k, l;
  21.  
  22.   for (k=0;k<=1;k++) {
  23.     r=pal[254][0];
  24.     g=pal[254][1];
  25.     b=pal[254][2];
  26.     for (l=254;l>=1;l--) {
  27.       pal[l][0]=pal[l-1][0];
  28.       pal[l][1]=pal[l-1][1];
  29.       pal[l][2]=pal[l-1][2];
  30.     }
  31.     pal[1][0]=r;
  32.     pal[1][1]=g;
  33.     pal[1][2]=b;
  34.   }
  35.   for (k=0;k<=255;k++)
  36.     setrgbpalette(k,pal[k][0],pal[k][1],pal[k][2]);
  37. }
  38.  
  39. void PlayRGBpalette(void)
  40. /* This is partially copyrighted by COPYRIGHT(C) 1990 by H+BEDV  */
  41. {
  42.   typedef char _PAL[256][3];
  43.  
  44.   int x,c, m, maxx, maxy, radius, height, ycenter;
  45.   float pc;
  46.   _PAL cpal;
  47.   struct viewporttype     viewinfo;
  48.  
  49.   if ( getmaxcolor() != 255) return;
  50.  
  51.   for (c=0;c<=255;c++) {
  52.     m= (c*3)>>1;
  53.     if ((m<64)) {
  54.       cpal[c][0]=63;
  55.       cpal[c][1]=m;
  56.       cpal[c][2]=0;
  57.     }
  58.     if ((m>63) && (m<128)) {
  59.       cpal[c][0]=127-m;
  60.       cpal[c][1]=63;
  61.       cpal[c][2]=0;
  62.     }
  63.     if ((m>127) && (m<192)) {
  64.       cpal[c][0]=0;
  65.       cpal[c][1]=63;
  66.       cpal[c][2]=m-128;
  67.     }
  68.     if ((m>191) && (m<256)) {
  69.       cpal[c][0]=0;
  70.       cpal[c][1]=255-m;
  71.       cpal[c][2]=63;
  72.     }
  73.     if ((m>255) && (m<320)) {
  74.       cpal[c][0]=m-256;
  75.       cpal[c][1]=0;
  76.       cpal[c][2]=63;
  77.     }
  78.     if ((m>319)) {
  79.       cpal[c][0]=63;
  80.       cpal[c][1]=0;
  81.       cpal[c][2]=383-m;
  82.     }
  83.   }
  84.   cpal[0][0]=0;
  85.   cpal[0][1]=0;
  86.   cpal[0][2]=0;
  87.   cpal[255][0]=63;
  88.   cpal[255][1]=63;
  89.   cpal[255][2]=63;
  90.   ShiftDac( cpal);
  91.  
  92.   MainWindowColor( "Play RGB palette", 255);
  93.   getviewsettings( &viewinfo );
  94.   maxx = abs(viewinfo.right-viewinfo.left)-1;
  95.   maxy = abs(viewinfo.top-viewinfo.bottom)-1;
  96.   setcolor(255);
  97.  
  98.   height = maxy/8;
  99.   c=1;
  100.   for (x=5; x <= maxx+1-5; ++x) {
  101.     setcolor(c);
  102.     if (++c > 254) c = 1;
  103.     line(x,maxy-5,x,maxy-5-height);
  104.   }
  105.  
  106.   pc=1.0;
  107.   ycenter = (maxy-5-height) / 2;
  108.   radius = _min(maxy-5-height, maxx)*9/20;
  109.   for (x=0;x<=356;x++) {
  110.     setcolor(pc);
  111.     setfillstyle(SOLID_FILL,pc);
  112.     pieslice(maxx/2,ycenter,x,x+4,radius);
  113.     pc=pc+254.0/360.0;
  114.   }
  115.  
  116.   StatusLineColor( StopMsg, 255);
  117.  
  118.   do {
  119.     ShiftDac(cpal);
  120.   } while (!(kbhit()));
  121.   getch();
  122.   for (c=1; c < 255; ++c) {
  123.     cpal[c][0] = _dac_g256[c][0];
  124.     cpal[c][1] = _dac_g256[c][1];
  125.     cpal[c][2] = _dac_g256[c][2];
  126.   }
  127.  
  128.   StatusLineColor( PauseMsg, 255);
  129.   do {
  130.     ShiftDac(cpal);
  131.   } while (!(kbhit()));
  132.  
  133.   setbkcolor(BLACK);
  134.   clearviewport();
  135.   setrgbdefaults();
  136.   Pause();                              /* Pause for user to read screen*/
  137. }
  138.  
  139. /* The Sierpinski demo was mainly taken from
  140.    N. Wirth: Algorithmen und Datenstrukturen  */
  141. #define SIRP_N     4
  142. #define SIRP_H0    320
  143.  
  144. static int SIRP_x, SIRP_y, h;
  145.  
  146. static void SIRP_a(int i);
  147. static void SIRP_b(int i);
  148. static void SIRP_c(int i);
  149. static void SIRP_d(int i);
  150.  
  151. static void SIRP_a(int i)
  152. {
  153.   if (i>0) {
  154.     SIRP_a(i-1); SIRP_x += h;   SIRP_y -= h; lineto( SIRP_x, SIRP_y);
  155.     SIRP_b(i-1); SIRP_x += 2*h;              lineto( SIRP_x, SIRP_y);
  156.     SIRP_d(i-1); SIRP_x += h;   SIRP_y += h; lineto( SIRP_x, SIRP_y);
  157.     SIRP_a(i-1);
  158.   }
  159. }
  160.  
  161. static void SIRP_b(int i)
  162. {
  163.   if (i>0) {
  164.     SIRP_b(i-1); SIRP_x -= h; SIRP_y -= h;   lineto( SIRP_x, SIRP_y);
  165.     SIRP_c(i-1);              SIRP_y -= 2*h; lineto( SIRP_x, SIRP_y);
  166.     SIRP_a(i-1); SIRP_x += h; SIRP_y -= h;   lineto( SIRP_x, SIRP_y);
  167.     SIRP_b(i-1);
  168.   }
  169. }
  170.  
  171. static void SIRP_c(int i)
  172. {
  173.   if (i>0) {
  174.     SIRP_c(i-1); SIRP_x -= h;   SIRP_y += h; lineto( SIRP_x, SIRP_y);
  175.     SIRP_d(i-1); SIRP_x -= 2*h;              lineto( SIRP_x, SIRP_y);
  176.     SIRP_b(i-1); SIRP_x -= h;   SIRP_y -= h; lineto( SIRP_x, SIRP_y);
  177.     SIRP_c(i-1);
  178.   }
  179. }
  180.  
  181. static void SIRP_d(int i)
  182. {
  183.   if (i>0) {
  184.     SIRP_d(i-1); SIRP_x += h; SIRP_y += h;   lineto( SIRP_x, SIRP_y);
  185.     SIRP_a(i-1);              SIRP_y += 2*h; lineto( SIRP_x, SIRP_y);
  186.     SIRP_c(i-1); SIRP_x -= h; SIRP_y += h;   lineto( SIRP_x, SIRP_y);
  187.     SIRP_d(i-1);
  188.   }
  189. }
  190.  
  191. void sierpinski(void)
  192. {
  193.   int i, h0, x0, y0, bx, by;
  194.   int border, color;
  195.   struct viewporttype vp;
  196.   struct fillsettingstype fs;
  197.  
  198.   MainWindow( "Floodfill demo");
  199.   StatusLine(PauseMsg);
  200.   getviewsettings( &vp);
  201.   getfillsettings( &fs);
  202.  
  203.   setviewport( (bx=_max((getmaxx() - SIRP_H0) / 2, vp.left)),
  204.            (by=_max((getmaxy() - SIRP_H0) / 2, vp.top)),
  205.            _min((getmaxx() + SIRP_H0) / 2 + 5, vp.right),
  206.            _min((getmaxy() + SIRP_H0) / 2 + 5, vp.bottom),
  207.            TRUE );
  208.  
  209.   switch (random(6)) {
  210.     case 0 : border = LIGHTCYAN;  break;
  211.     case 1 : border = YELLOW;     break;
  212.     case 2 : border = RED;        break;
  213.     case 3 : border = GREEN;      break;
  214.     case 4 : border = BLUE;       break;
  215.     default: border = WHITE;      break;
  216.   }
  217.   setcolor( border);
  218.   h0 = SIRP_H0;
  219.   h = h0 / 4;
  220.   x0 = 2*h;
  221.   y0 = 3*h;
  222.   for (i=1; i <= SIRP_N; ++i) {
  223.     x0 -= h;
  224.     h /= 2;
  225.     y0 += h;
  226.     SIRP_x = x0; SIRP_y = y0;
  227.     moveto( SIRP_x, SIRP_y);
  228.     SIRP_a(i); SIRP_x += h; SIRP_y -= h; lineto(SIRP_x,SIRP_y);
  229.     SIRP_b(i); SIRP_x -= h; SIRP_y -= h; lineto(SIRP_x,SIRP_y);
  230.     SIRP_c(i); SIRP_x -= h; SIRP_y += h; lineto(SIRP_x,SIRP_y);
  231.     SIRP_d(i); SIRP_x += h; SIRP_y += h; lineto(SIRP_x,SIRP_y);
  232.   }
  233.   setviewport( vp.left, vp.top, vp.right, vp.bottom, vp.clip);
  234.   bx += h0/2 - vp.left;
  235.   by += h0/2 - vp.top;
  236.   do {
  237.     do
  238.       color = random(getmaxcolor()+1);
  239.     while (color == WHITE || color == BLACK || color == border);
  240.     setfillstyle(random(USER_FILL-1)+1, color);
  241.     floodfill( bx, by, border);
  242.     floodfill(  1,  1, border);
  243.   } while ( !kbhit());
  244.   setfillstyle( fs.pattern, fs.color);
  245.  
  246.   Pause();                              /* Pause for user to read screen*/
  247. }
  248.  
  249. void RandomSolidBars(void)
  250. {
  251.   int color;
  252.  
  253.   MainWindow( "Random Solid/Line Bars" );
  254.   StatusLine( PauseMsg );               /* Put msg at bottom of screen   */
  255.   while( !kbhit() ){                    /* Until user enters a key...   */
  256.     color = random( MaxColors-1 )+1;
  257.     setcolor( color );
  258.     /* SOLID_FILL && LINE_FILL are much faster */
  259.     setfillstyle( SOLID_FILL+random(2), color );
  260.     bar3d( random( getmaxx() ), random( getmaxy() ),
  261.        random( getmaxx() ), random( getmaxy() ), 0, OFF);
  262.   }
  263.  
  264.   Pause();                              /* Pause for user's response    */
  265.  
  266. }
  267.  
  268.